package com.lankystar.todolist.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lankystar.todolist.dao.AccountMapper;
import com.lankystar.todolist.dao.GroupuserMapper;
import com.lankystar.todolist.model.Account;
import com.lankystar.todolist.service.IAccountService;

@Component
public class AccountServiceImpl implements IAccountService {

	@Autowired
	private AccountMapper accountDao;
	@Autowired
	private GroupuserMapper groupDao;

	/**
	 * 用户登录
	 */
	@Override
	public Account login(String username, String userpwd) {
		return accountDao.selectByUsernameAndUserpwd(username, userpwd);
	}

	/**
	 * 用户注册
	 */
	@Override
	public void register(Account record) {
		this.accountDao.insert(record);
	}

	/**
	 * 用户信息修改
	 */
	@Override
	public void modify(Account record) {
		accountDao.updateByPrimaryKey(record);
	}

	@Override
	public List<Account> selectAccounts() {
		return accountDao.selectAccounts();
	}

	@Override
	public Account selectAccountById(Integer id) {
		return accountDao.selectByPrimaryKey(id);
	}

	@Override
	public void deleteById(Integer id) {
		this.accountDao.deleteByPrimaryKey(id);
	}
	
	@Override
	public List<Account> selectAccountByGroupInfiId(Integer groupId) {
		// TODO Auto-generated method stub
		return accountDao.selectAccountByGroupInfiId(groupId);
	}

	@Override
	public Integer getAccountid(String name) {
		// TODO Auto-generated method stub
		return accountDao.selectByPrimaryname(name);
	}

	@Override
	public String getTaskRole(Integer userId) {
		String TRole=groupDao.getTaskRole(userId).get(0).get("role");
		return TRole;
	}
}
